export class HttpError extends Error {
  code;
  data;

  constructor(message, code, data) {
    super(message);
    this.code = code;
    this.data = data;
  }

  static from(error) {
    const status = error.response?.status || 500;
    const data = error.response?.data;
    
    switch (status) {
      case ErrorCode.TOKEN_INVALID:
        return new HttpError('Token invalid or expired', status, data);
      case ErrorCode.FORBIDDEN:
        return new HttpError('Access forbidden', status, data);
      case ErrorCode.NOT_FOUND:
        return new HttpError('Resource not found', status, data);
      case ErrorCode.SERVER_ERROR:
        return new HttpError('Server error', status, data);
      default:
        return new HttpError(error.message, status, data);
    }
  }
}